<?php

/**
 * logger class
 */
class Logger {

  /**
   *
   * @var array
   */
  protected static $_data = array();

  /**
   * add string, array to logger
   * @param string|array $var
   */
  public static function add($var, $var2 = NULL) {
    if($var2){
      self::$_data[] = $var. ': '. $var2;
    }else  if (is_array($var)) {
      foreach ($var as $key => $value) {
        self::$_data[$key] = $value;
      }
    } else {
      self::$_data [] = $var;
    }
  }

  /**
   * dump all logger to string
   */
  public static function dump() {
    foreach (self::$_data as $key => $message) {
      echo sprintf('%s : %s <br/>', $key, $message);
    }
  }

  public static function write() {

    $filename = LOG_PATH . DS . date('Y_m_d') . '.txt';
    if ($handle = @fopen($filename, 'a+')) {
      foreach (self::$_data as $key => $message) {
        fwrite($handle, sprintf("%s : %s\r\n", $key, $message));
      }
      @fclose($handle);
    }
  }

}